//
//  WCOrderAndAddrVC.m
//  CBT
//
//  Created by apple on 2019/7/8.
//  Copyright © 2019 Mr.Zhang. All rights reserved.
//

#import "WCOrderAndAddrVC.h"
#import "WCOrderListVC.h"
#import "WCAddrsAndOrdersCell.h"
#import "WCAddrEditVC.h"
#import "WCAddrListVC.h"

@interface WCOrderAndAddrVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation WCOrderAndAddrVC



- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = kLocalizedString(@"PC硬件",nil);
    
    [self.view addSubview:self.tableView];
    self.tableView.rowHeight = 60;
    [self.tableView registerClass:[WCAddrsAndOrdersCell class] forCellReuseIdentifier:@"rootCell"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    
    WCAddrsAndOrdersCell *cell = [WCAddrsAndOrdersCell createTableView:tableView];
    if (indexPath.row) {
        cell.coinNameLabel.text = kLocalizedString(@"管理收货地址", nil) ;
        cell.titleImg.image = [UIImage imageNamed:@"mine_addr"];
    }
    else {
        cell.coinNameLabel.text = kLocalizedString(@"我的订单", nil);
        cell.titleImg.image = [UIImage imageNamed:@"mine_order"];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row) {
        NSString *resStr = [[NSUserDefaults standardUserDefaults] stringForKey:@"address"];
        if ([resStr isEqualToString:@"1"]) {
            WCAddrListVC *vc = [[WCAddrListVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
        else {
            WCAddrEditVC *vc = [[WCAddrEditVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
    else {
        WCOrderListVC *vc = [[WCOrderListVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (UITableView *)tableView {
    if (!_tableView) {
        CGRect rect = self.view.frame;
        rect.size.height -= HFNavigationHeight;
        _tableView = [[UITableView alloc] initWithFrame:rect style:UITableViewStylePlain];
        
        _tableView.delegate     = self;
        _tableView.dataSource   = self;
        _tableView.scrollsToTop = YES;
        
        _tableView.separatorColor = [UIColor clearColor];
        _tableView.backgroundColor = [UIColor colorWithRed:237/255.0 green:237/255.0 blue:237/255.0 alpha:1];
        _tableView.tableFooterView = [[UIView alloc] init];
        _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
        
        
        if (@available(iOS 11.0, *)){
            self.tableView.estimatedRowHeight = 0;
            self.tableView.estimatedSectionHeaderHeight = 0;
            self.tableView.estimatedSectionFooterHeight = 0;
        }

    }
    return _tableView;
}


@end

